package com.yljk.yljkproject.newpickview;

import android.annotation.SuppressLint;
import android.app.Activity;
import android.graphics.drawable.ColorDrawable;
import android.os.Build;
import android.os.Handler;
import android.text.TextUtils;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.MotionEvent;
import android.view.View;
import android.view.Window;
import android.view.WindowManager;
import android.widget.LinearLayout;
import android.widget.PopupWindow;
import android.widget.TextView;

import androidx.annotation.RequiresApi;

import com.yilijk.base.utils.ALog;
import com.yljk.yljkproject.MyActivityManager;
import com.yljk.yljkproject.R;
import com.yljk.yljkproject.view.pickview.WheelView;

import org.json.JSONObject;

import java.util.ArrayList;
import java.util.Calendar;
import java.util.List;
import java.util.Map;

public class PickViewUtils implements View.OnClickListener {
    final String MARK = "mark", title = "title", selInfo = "selInfo";
    private final String[] weeks = {"每周一", "每周二", "每周三", "每周四", "每周五", "每周六", "每周日"};
    private final String[] times = {"00:00", "00:30", "01:00", "01:30", "02:00", "02:30", "03:00", "03:30", "04:00", "04:30", "05:00", "05:30", "06:00",
            "06:30", "07:00", "07:30", "08:00", "08:30", "09:00", "09:30", "10:00", "10:30", "11:00", "11:30", "12:00", "12:30",
            "13:00", "13:30", "14:00", "14:30", "15:00", "15:30", "16:00", "16:30", "17:00", "17:30", "18:00", "18:30", "19:00",
            "19:30", "20:00", "20:30", "21:00", "21:30", "22:00", "22:30", "23:00", "23:30"};
    private final String[] dayArray = {"上午", "下午", "晚上"};
    @SuppressLint("StaticFieldLeak")
    private static PickViewUtils pickViewUtils;


    public static PickViewUtils getPickViewUtils() {
        if (pickViewUtils == null) {
            pickViewUtils = new PickViewUtils();
        }
        return pickViewUtils;
    }


    private PopupWindow popupWindow;
    private TextView pickviewCancel;
    private TextView pickviewTitle;
    private TextView pickviewSure;
    private LinearLayout selectType;
    private View popupWindowView;

    //pickview创建
    @SuppressLint("InflateParams")
    public void pickViewCreate(Activity activity) {
        if (handler == null) {
            handler = new Handler();
        }
        popupWindow = new PopupWindow(activity);
        popupWindowView = LayoutInflater.from(activity).inflate(R.layout.pickview_popwindow, null);
        //pickviewCancel pop取消
        pickviewCancel = popupWindowView.findViewById(R.id.pickview_cancel);
        //pickviewCancel pop标题
        pickviewTitle = popupWindowView.findViewById(R.id.pickview_title);
        //pickviewCancel pop确定
        pickviewSure = popupWindowView.findViewById(R.id.pickview_sure);
        //类型布局
        selectType = popupWindowView.findViewById(R.id.select_type);
        pickviewCancel.setOnClickListener(this);
        pickviewSure.setOnClickListener(this);
        popupWindow.setBackgroundDrawable(new ColorDrawable(0x00000000));
        popupWindow.setOnDismissListener(() -> setBackgroundAlpha(1.0f));

    }

    /**
     * 调用展示pickview
     *
     * @param activity         当前activity
     * @param pickViewCallback pickview回调
     * @param type             显示pickview类型
     * @param title            pickview标题
     * @param cancelText       退出文案
     * @param sureText         确定文案
     * @param currentTime      当前时间 没有传空
     * @param map              是否是自定义数据 没有传null
     * @param decorView        当前视图view
     */
    @RequiresApi(api = Build.VERSION_CODES.KITKAT)
    public void getPickViewShow(Activity activity,
                                String type, String title, String cancelText, String sureText, String currentTime, Map<String, Object> map, View decorView
            , PickViewCallback pickViewCallback) {
        pickViewCreate(activity);
        showPickViewAndTYPE(activity, type, title, cancelText, sureText, currentTime, map, decorView, pickViewCallback);

    }


    private void setBackgroundAlpha(float v) {
        Window window = MyActivityManager.getInstance().getCurrentActivity().getWindow();
        WindowManager.LayoutParams lp = window.getAttributes();
        window.setFlags(WindowManager.LayoutParams.FLAG_DIM_BEHIND, WindowManager.LayoutParams.FLAG_DIM_BEHIND);
        lp.alpha = v; //0.0-1.0
        window.setAttributes(lp);
    }


    //设置pickView 标题
    private void setPickviewTitle(String title) {
        pickviewTitle.setText(title);
    }

    //设置pickView 退出
    private void setPickviewCancel(String cancel) {
        pickviewCancel.setText(cancel);
    }

    //设置pickView 确定
    private void setPickviewSure(String sure) {
        pickviewSure.setText(sure);
    }


    private final String Type_WEEKTIME = "weekTime";
    private final String Type_TIME = "time";
    private final String Type_DATATIME = "dateTime";
    private final String Type_NORMAL = "normal";
    private final String Type_TIMEINTERVAL = "timeInterval";
    private final String Type_MORETIME = "moreTime";
    private final String Type_ThreeFastTime = "specifiedTime";

    /**
     * pickview week
     */
    WheelView weekTime;
    WheelView weekstartTime;
    WheelView weekstopTime;
    WheelView splitView;

    /**
     * Time X 4
     */
    WheelView time4StartTime1;
    WheelView time4SplitView1;
    WheelView time4StopTime1;
    WheelView time4StartTime2;
    WheelView time4SplitView2;
    WheelView time4StopTime2;

    /**
     * 00:00 至00：00
     */
    WheelView intervalstartTime;
    WheelView intervalsplitView;
    WheelView intervalstopTime;

    /**
     * datatime
     */
    WheelView dataTime;
    WheelView datastartTime;
    WheelView datastopTime;
    WheelView datasplitView;

    /**
     * normal
     */
    WheelView normalTime;

    /**
     * year
     */
    WheelView yearTime;
    WheelView yearSplit;
    WheelView monthTime;
    WheelView monthSplit;
    WheelView dayTime;
    WheelView daySplit;
    ArrayList<Integer> years = new ArrayList<>();
    ArrayList<Integer> months = new ArrayList<>();
    ArrayList<Integer> days = new ArrayList<>();


    /**
     * 上下晚
     *
     * @param activity
     * @param type
     * @param currentTime
     * @param map
     */
    WheelView threeFastTime;
    WheelView threeTime1;
    WheelView threeTime2;

    //设置pickview 类型
    public void selectPickViewType(Activity activity, String type, String currentTime, Map<String, Object> map) {
        //选择pickview类型
        selectType.removeAllViews();
        switch (type) {
            case Type_ThreeFastTime:
                View pickview_three_fast_time = LayoutInflater.from(activity).inflate(R.layout.pickview_three_fast_time, selectType);
                threeFastTime = pickview_three_fast_time.findViewById(R.id.three_wl_fast);
                threeTime1 = pickview_three_fast_time.findViewById(R.id.three_wl_time1);
                threeTime2 = pickview_three_fast_time.findViewById(R.id.three_wl_time2);
                String currentthreeTime1 = "";
                String currentthreeTime2 = "";
                if (!TextUtils.isEmpty(currentTime)) {
                    String[] split = currentTime.split("-");
                    if (!TextUtils.isEmpty(split[0])) {
                        currentthreeTime1 = split[0];

                    }
                    if (!TextUtils.isEmpty(split[1])) {
                        currentthreeTime2 = split[0];
                    }
                }
                threeFastTime.addData("上午");
                threeFastTime.addData("下午");
                threeFastTime.addData("晚上");
                threeTime1.setCenterItem(setMinutesInterval30(12, 45, currentthreeTime1, threeTime1));
                threeTime2.setCenterItem(setMinutesInterval30(12, 45, currentthreeTime2, threeTime2));
                threeFastTime.setCenterItem(0);
                threeTime1.setCenterItem(0);
                threeTime2.setCenterItem(12);
                threeFastTime.setPickviewChangeListener(new PickviewChangeListener() {
                    @Override
                    public void onChange() {
                        String centerItem = (String) threeFastTime.getCenterItem();
                        switch (centerItem) {
                            case "上午":
                                threeFastTime.setCenterItem(0);
                                threeTime1.setCenterItem(0);
                                threeTime2.setCenterItem(12);
                                break;
                            case "下午":
                                threeFastTime.setCenterItem(1);
                                threeTime1.setCenterItem(12);
                                threeTime2.setCenterItem(24);

                                break;
                            case "晚上":
                                threeFastTime.setCenterItem(2);
                                threeTime1.setCenterItem(24);
                                threeTime2.setCenterItem(32);

                                break;
                        }

                    }
                });
                break;
            case Type_WEEKTIME://周  开始时间 结束时间
                View pickview_week = LayoutInflater.from(activity).inflate(R.layout.pickview_week, selectType);
                weekTime = pickview_week.findViewById(R.id.week_time);
                splitView = pickview_week.findViewById(R.id.split_view);
                weekstartTime = pickview_week.findViewById(R.id.weekstart_time);
                weekstopTime = pickview_week.findViewById(R.id.weekstop_time);
                String currentWeek1 = "";
                String currentWeek2 = "";
                String currentWeek3 = "";
                if (TextUtils.isEmpty(currentTime)) {
                    //如果没有给定指定的时间定位  默认为当前时间
                    //设置为当前时间
                    Calendar instance = Calendar.getInstance();
                    String mWay = String.valueOf(instance.get(Calendar.DAY_OF_WEEK));
                    switch (mWay) {
                        case "1":
                            mWay = "每周日";
                            break;
                        case "2":
                            mWay = "每周一";
                            break;
                        case "3":
                            mWay = "每周二";
                            break;
                        case "4":
                            mWay = "每周三";
                            break;
                        case "5":
                            mWay = "每周四";
                            break;
                        case "6":
                            mWay = "每周五";
                            break;
                        case "7":
                            mWay = "每周六";
                            break;
                    }
                    for (String week : weeks) {
                        if (mWay.equals(week)) {
                            currentWeek1 = week;
                            break;
                        }
                    }
                } else {
                    String[] split = currentTime.split("-");
                    if (!TextUtils.isEmpty(split[0])) {
                        for (String week : weeks) {
                            if (split[0].equals(week)) {
                                currentWeek1 = week;
                            }
                        }
                        if (!TextUtils.isEmpty(split[1])) {
                            for (String time : times) {
                                if (split[1].equals(time)) {
                                    currentWeek2 = time;
                                }
                            }
                            if (!TextUtils.isEmpty(split[2])) {
                                for (String time : times) {
                                    if (split[2].equals(time)) {
                                        currentWeek3 = time;
                                    }
                                }
                            }
                        }
                    }
                }
                weekTime.setCenterItem(setWeek(currentWeek1, weekTime));
                weekstartTime.setCenterItem(setMinutesInterval30(currentWeek2, weekstartTime));
                weekstopTime.setCenterItem(setMinutesInterval30(currentWeek3, weekstopTime));
                splitView.addData("-");
                splitView.setCenterItem(0);
                break;
            case Type_MORETIME:
                View pickview_time4 = LayoutInflater.from(activity).inflate(R.layout.pickview_time4, selectType);
                time4StartTime1 = pickview_time4.findViewById(R.id.time4_start_Time1);
                time4SplitView1 = pickview_time4.findViewById(R.id.time4_split_view1);
                time4StopTime1 = pickview_time4.findViewById(R.id.time4_stop_Time1);
                time4StartTime2 = pickview_time4.findViewById(R.id.time4_start_Time2);
                time4SplitView2 = pickview_time4.findViewById(R.id.time4_split_view2);
                time4StopTime2 = pickview_time4.findViewById(R.id.time4_stop_Time2);
                String currentStartTime1 = "";
                String currentStartTime2 = "";
                String currentStopTime1 = "";
                String currentStopTime2 = "";
                if (!TextUtils.isEmpty(currentTime)) {
                    String[] split = currentTime.split("-");
                    if (!TextUtils.isEmpty(split[0])) {
                        String[] split1 = split[0].split(":");
                        currentStartTime1 = split1[0];
                        currentStopTime1 = split1[1];

                    }
                    if (!TextUtils.isEmpty(split[1])) {
                        String[] split2 = split[1].split(":");
                        currentStartTime2 = split2[0];
                        currentStopTime2 = split2[1];
                    }
                }
                time4StartTime1.setCenterItem(setHouts(currentStartTime1, time4StartTime1));
                time4StopTime1.setCenterItem(setMinutes(currentStopTime1, time4StopTime1));
                time4StartTime2.setCenterItem(setHouts(currentStartTime2, time4StartTime2));
                time4StopTime2.setCenterItem(setMinutes(currentStopTime2, time4StopTime2));
                time4SplitView1.addData(":");
                time4SplitView2.addData(":");
                time4SplitView1.setCenterItem(0);
                time4SplitView2.setCenterItem(0);
                break;
            case Type_NORMAL:
                ArrayList<String> strings_normal = new ArrayList<>();
                Object data = map.get("data");
                if (data instanceof ArrayList<?>) {
                    List<?> d = (List<?>) data;
                    for (Object o : d) {
                        if (o instanceof String) {
                            strings_normal.add(o.toString());
                        }
                    }
                }

                View pickview_normal = LayoutInflater.from(activity).inflate(R.layout.pickview_normal, selectType);
                normalTime = pickview_normal.findViewById(R.id.normal_time);
                int index = 0;
                for (int i = 0; i < strings_normal.size(); i++) {
                    normalTime.addData(strings_normal.get(i));
                    if (strings_normal.get(i).equals(currentTime)) {
                        index = i;
                    }
                }
                normalTime.setCenterItem(index);
                break;
            case Type_DATATIME:
                ArrayList<String> strings = new ArrayList<>();
                Object data_time = map.get("data");
                if (data_time instanceof ArrayList<?>) {
                    List<?> d = (List<?>) data_time;
                    for (Object o : d) {
                        if (o instanceof String) {
                            strings.add(o.toString());
                        }
                    }
                }
                View pickview_datatime = LayoutInflater.from(activity).inflate(R.layout.pickview_datatime, selectType);
                dataTime = pickview_datatime.findViewById(R.id.data_time);
                datastartTime = pickview_datatime.findViewById(R.id.datastart_time);
                datastopTime = pickview_datatime.findViewById(R.id.datastop_time);
                datasplitView = pickview_datatime.findViewById(R.id.datasplit_view);
                ArrayList<String> strings1 = new ArrayList<>();
                for (int i = 0; i < strings.size(); i++) {
                    if (i == 0) {
                        dataTime.addData("今天");
                        strings1.add("今天");
                    } else {
                        dataTime.addData(strings.get(i));
                        strings1.add(strings.get(i));
                    }
                }
                dataTime.setCenterItem(0);
                datasplitView.addData(":");
                datasplitView.setCenterItem(0);
                if (currentTime != null && !currentTime.isEmpty()) {
                    String[] split = currentTime.split("-");
                    String dataTimeStr = split[0];
                    String[] split1 = split[1].split(":");

                    String[] monthss = dataTimeStr.split("月");
                    int i1 = Integer.parseInt(monthss[0]);
                    String[] dayss = monthss[1].split("日");
                    int j1 = Integer.parseInt(dayss[0]);
                    String defaultTime = i1 + "月" + j1 + "日";
                    for (int i = 0; i < strings1.size(); i++) {
                        if (defaultTime.equals(strings1.get(i))) {
                            dataTime.setCenterItem(i);
                        }
                    }
                    datastartTime.setCenterItem(setHouts(split1[0], datastartTime));
                    datastopTime.setCenterItem(setMinutes(split1[1], datastopTime));
                } else {
                    datastartTime.setCenterItem(setHouts("", datastartTime));
                    datastopTime.setCenterItem(setMinutes("", datastopTime));
                }
                break;
            case Type_TIMEINTERVAL:
                View pickview_timeinterval = LayoutInflater.from(activity).inflate(R.layout.pickview_timeinterval, selectType);
                intervalstartTime = pickview_timeinterval.findViewById(R.id.intervalstart_time);
                intervalsplitView = pickview_timeinterval.findViewById(R.id.intervalsplit_view);
                intervalstopTime = pickview_timeinterval.findViewById(R.id.intervalstop_time);
                intervalstartTime.setCenterItem(setMinutesInterval30(12, 44, "", intervalstartTime));
                intervalstopTime.setCenterItem(setMinutesInterval30(12, 45, "", intervalstopTime));
                intervalsplitView.addData("至");
                intervalsplitView.setCenterItem(0);
                break;
            case Type_TIME:
                View pickview_year = LayoutInflater.from(activity).inflate(R.layout.pickview_year, selectType);
                yearTime = pickview_year.findViewById(R.id.year_time);
                yearSplit = pickview_year.findViewById(R.id.year_split);
                monthTime = pickview_year.findViewById(R.id.month_time);
                monthSplit = pickview_year.findViewById(R.id.month_split);
                dayTime = pickview_year.findViewById(R.id.day_time);
                daySplit = pickview_year.findViewById(R.id.day_split);

                Calendar CD = Calendar.getInstance();

                currentYearInt = CD.get(Calendar.YEAR);
                currentMonthInt = CD.get(Calendar.MONTH) + 1;
                currentDayInt = CD.get(Calendar.DATE);
                //默认值
                years.clear();
                months.clear();
                days.clear();
                for (int i = currentYearInt - 100; i <= currentYearInt; i++) {
                    yearTime.addData(i + "");
                    years.add(i);
                }
                yearTime.setCenterItem(years.size() - 1);
                for (int i = 1; i <= 12; i++) {
                    monthTime.addData(i + "");
                    months.add(i);
                }
                monthTime.setCenterItem(months.size() - 1);
                for (int i = 1; i <= 31; i++) {
                    dayTime.addData(i + "");
                    days.add(i);
                }
                dayTime.setCenterItem(days.size() - 1);

                years.clear();
                months.clear();
                days.clear();
                yearTime.clearData();
                for (int i = currentYearInt - 100; i <= currentYearInt; i++) {
                    yearTime.addData(i + "");
                    years.add(i);
                }
                yearTime.setCenterItem(years.size() - 1);
                monthTime.clearData();
                for (int i = 1; i <= currentMonthInt; i++) {
                    monthTime.addData(i + "");
                    months.add(i);
                }
                monthTime.setCenterItem(months.size() - 1);
                dayTime.clearData();
                for (int i = 1; i <= currentDayInt; i++) {
                    dayTime.addData(i + "");
                    days.add(i);
                }
                dayTime.setCenterItem(days.size() - 1);

                yearSplit.addData("年");
                monthSplit.addData("月");
                daySplit.addData("日");
                yearSplit.setCenterItem(0);
                monthSplit.setCenterItem(0);
                daySplit.setCenterItem(0);
                yearTimeToutch();
                break;
        }

    }

    private Handler handler;

    @SuppressLint("ClickableViewAccessibility")
    private void yearTimeToutch() {
        yearTime.setOnTouchListener((v, event) -> {
            if (event.getAction() == MotionEvent.ACTION_UP) {
                int currentYear = getCurrentYear();
                int monthindex;
                if (currentYear == currentYearInt) {
                    monthindex = currentMonthInt;
                } else {
                    monthindex = 12;
                }
                months.clear();
                for (int i = 1; i <= monthindex; i++) {
                    months.add(i);
                }
                //刷新UI
                handler.post(() -> {
                    monthTime.clearData();
                    for (int i = 0; i < months.size(); i++) {
                        monthTime.addData(months.get(i) + "");
                        ALog.i("pickviewm", "run: " + months.get(i));
                    }
                    monthTime.setCenterItem(0);
                    monthTime.notifyDataSetChanged();
                });
                int currentMonth = getCurrentMonth();
                int dayindex;
                if (currentMonth == 2) {
                    if (currentYear % 4 == 0) {
                        //29D
                        dayindex = 29;
                    } else {
                        //28D
                        dayindex = 28;
                    }
                } else if (currentMonth == 1 || currentMonth == 3 || currentMonth == 5 || currentMonth == 7 || currentMonth == 8 || currentMonth == 10 || currentMonth == 12) {
                    //31D
                    dayindex = 31;
                } else {
                    //30D
                    dayindex = 30;
                }
                days.clear();
                for (int i = 1; i <= dayindex; i++) {
                    days.add(i);
                }
                //刷新日期UI
                handler.post(() -> {
                    dayTime.clearData();
                    for (int i = 0; i < days.size(); i++) {
                        dayTime.addData(days.get(i) + "");
                    }
                    dayTime.setCenterItem(0);
                    dayTime.notifyDataSetChanged();
                });

            }

            return false;
        });

        monthTime.setOnTouchListener((v, event) -> {
            if (event.getAction() == MotionEvent.ACTION_UP) {
                int currentYear = getCurrentYear();
                int currentMonth = getCurrentMonth();
                int dayindex;
                if (currentYear == currentYearInt && currentMonth == currentMonthInt) {
                    dayindex = currentDayInt;
                } else if (currentMonth == 2) {
                    if (currentYear % 4 == 0) {
                        //29D
                        dayindex = 29;
                    } else {
                        //28D
                        dayindex = 28;
                    }
                } else if (currentMonth == 1 || currentMonth == 3 || currentMonth == 5 || currentMonth == 7 || currentMonth == 8 || currentMonth == 10 || currentMonth == 12) {
                    //31D
                    dayindex = 31;
                } else {
                    //30D
                    dayindex = 30;
                }
                days.clear();
                for (int i = 1; i <= dayindex; i++) {
                    days.add(i);
                }
                //刷新日期UI
                handler.post(() -> {
                    dayTime.clearData();
                    for (int i = 0; i < days.size(); i++) {
                        dayTime.addData(days.get(i) + "");
                    }
                    dayTime.setCenterItem(0);
                    dayTime.notifyDataSetChanged();
                });
            }
            return false;
        });


    }

    private int getCurrentYear() {
        return Integer.parseInt((String) yearTime.getCenterItem());
    }

    private int getCurrentMonth() {
        return Integer.parseInt((String) monthTime.getCenterItem());
    }


    @RequiresApi(api = Build.VERSION_CODES.KITKAT)
    private void pickViewShow(View view) {
        // 实例化一个ColorDrawable颜色为半透明
        // 设置弹出窗体的背景
        popupWindow.setOutsideTouchable(true);
        popupWindow.setFocusable(true);
        popupWindow.setAnimationStyle(R.style.popwindow_anim_style);
        popupWindow.setHeight(LinearLayout.LayoutParams.WRAP_CONTENT);
        popupWindow.setWidth(LinearLayout.LayoutParams.MATCH_PARENT);
        popupWindow.setContentView(popupWindowView);
        popupWindow.showAtLocation(view, Gravity.BOTTOM, 0, 0);
        setBackgroundAlpha(0.5f);
    }


//    public void getSureOnClick(PickViewCallback pickViewCallback) {
//        pickviewSure.setOnClickListener(new View.OnClickListener() {
//            @Override
//            public void onClick(View v) {
//                try {
//                    String sureResult = getSureResult(TYPE);
//                    pickViewCallback.getSureResult(sureResult);
//                    popupWindow.dismiss();
//                } catch (Exception e) {
//                    e.printStackTrace();
//                }
//
//            }
//        });
//    }

    private String getSureResult(String type) throws Exception {
        String result = "";
        String commondResult;
        switch (type) {
            case Type_ThreeFastTime: {
                commondResult = getCommondResult((String) threeTime1.getCenterItem(), (String) threeTime2.getCenterItem());
                JSONObject weekJsonObject = new JSONObject();
                weekJsonObject.put(MARK, commondResult);
                weekJsonObject.put(title, commondResult);
                JSONObject weekJson = new JSONObject();
                weekJson.put(selInfo, weekJsonObject);
                weekJson.put(title, getTitleString());
                result = weekJson.toString();
            }
            break;
            case Type_WEEKTIME:
                commondResult = getCommondResult(getWeekTimeString(), getStartTimeString(), getEndTimeString());
                JSONObject weekJsonObject = new JSONObject();
                weekJsonObject.put(MARK, commondResult);
                weekJsonObject.put(title, commondResult);
                JSONObject weekJson = new JSONObject();
                weekJson.put(selInfo, weekJsonObject);
                weekJson.put(title, getTitleString());
                result = weekJson.toString();
                break;
            case Type_MORETIME:
                commondResult = getCommondResult(time4StartTime1.getCenterItem() + ":" + time4StopTime1.getCenterItem(), time4StartTime2.getCenterItem() + ":" + time4StopTime2.getCenterItem());
                JSONObject time4JsonObject = new JSONObject();
                time4JsonObject.put(MARK, commondResult);
                time4JsonObject.put(title, commondResult);
                JSONObject time4Json = new JSONObject();
                time4Json.put(selInfo, time4JsonObject);
                time4Json.put(title, getTitleString());
                result = time4Json.toString();
                break;
            case Type_DATATIME:
                Calendar selectedDate = Calendar.getInstance();//系统时间   有mark 为标记时间  无mark 为当前时间
                int month = selectedDate.get(Calendar.MONTH);
                int day = selectedDate.get(Calendar.DAY_OF_MONTH);

                commondResult = getCommondResult("今天".equals(dataTime.getCenterItem()) ? (month + 1) + "月" + day + "日" : (String) dataTime.getCenterItem(), datastartTime.getCenterItem() + ":" + datastopTime.getCenterItem());
                JSONObject dataJsonObject = new JSONObject();
                dataJsonObject.put(MARK, commondResult);
                dataJsonObject.put(title, commondResult);
                JSONObject dataJson = new JSONObject();
                dataJson.put(selInfo, dataJsonObject);
                dataJson.put(title, getTitleString());
                result = dataJson.toString();
                break;
            case Type_NORMAL:
                commondResult = getCommondResult((String) normalTime.getCenterItem());
                JSONObject normalJsonObject = new JSONObject();
                normalJsonObject.put(MARK, commondResult);
                normalJsonObject.put(title, commondResult);
                JSONObject normalJson = new JSONObject();
                normalJson.put(selInfo, normalJsonObject);
                normalJson.put(title, getTitleString());
                result = normalJson.toString();
                break;
            case Type_TIMEINTERVAL:
                commondResult = getCommondResult((String) intervalstartTime.getCenterItem(), (String) intervalstopTime.getCenterItem());
                JSONObject IntervalJsonObject = new JSONObject();
                IntervalJsonObject.put(MARK, commondResult);
                IntervalJsonObject.put(title, commondResult);
                JSONObject IntervalJson = new JSONObject();
                IntervalJson.put(selInfo, IntervalJsonObject);
                IntervalJson.put(title, getTitleString());
                result = IntervalJson.toString();
                break;
            case Type_TIME:
                commondResult = getCommondResult((String) yearTime.getCenterItem(), (String) monthTime.getCenterItem(), (String) dayTime.getCenterItem());
                JSONObject timeJsonObject = new JSONObject();
                timeJsonObject.put(MARK, commondResult);
                timeJsonObject.put(title, commondResult);
                JSONObject timeJson = new JSONObject();
                timeJson.put(selInfo, timeJson);
                timeJson.put(title, getTitleString());
                result = timeJson.toString();
                break;
        }

        return result;
    }


    @Override
    public void onClick(View v) {
        if (v.getId() == R.id.pickview_cancel) {//取消点击
            popupWindow.dismiss();
        }
    }


    private String getCommondResult(String... strings) {
        StringBuilder stringBuffer = new StringBuilder();

        for (int i = 0; i < strings.length; i++) {
            if (i == 0) {
                stringBuffer.append(strings[i]);
            } else {
                stringBuffer.append("-").append(strings[i]);
            }
        }
        return stringBuffer.toString();
    }

    private String getTitleString() {
        return pickviewTitle.getText().toString().trim();
    }

    private String getWeekTimeString() {
        return (String) weekTime.getCenterItem();
    }

    private String getStartTimeString() {
        return (String) weekstartTime.getCenterItem();
    }

    private String getEndTimeString() {
        return (String) weekstopTime.getCenterItem();
    }


    @RequiresApi(api = Build.VERSION_CODES.KITKAT)
    public void showPickViewAndTYPE(Activity activity, String type, String title, String cancelText, String sureText, String currentTime, Map<String, Object> map, View decorView, PickViewCallback pickViewCallback) {
        selectPickViewType(activity, type, currentTime, map);
        pickViewShow(decorView);
        setPickviewTitle(title);
        setPickviewCancel(cancelText);
        setPickviewSure(sureText);
        pickviewSure.setOnClickListener(v -> {
            try {
                pickViewCallback.getSureResult(getSureResult(type));
                popupWindow.dismiss();
            } catch (Exception e) {
                e.printStackTrace();
            }
        });
    }

    //设置时间 -- 星期几
    private int setWeek(String currentWeek, WheelView... wheelViews) {
        int index = 0;
        int positionIndex = 0;
        for (String week : weeks) {
            if (currentWeek.equals(week)) {
                positionIndex = index;
            } else {
                index++;
            }
            for (WheelView wheelView : wheelViews) {
                wheelView.addData(week);
            }
        }
        return positionIndex;
    }

    //设置时间 -- 分钟
    private int setMinutes(String currentMinutes, WheelView... wheelViews) {
        int index = 0;
        int positionIndex = 0;
        for (int i = 0; i < 60; i++) {
            String addDataString;
            if (i < 10) {
                addDataString = "0" + i;
            } else {
                addDataString = i + "";
            }
            //判断当前时间
            if (!currentMinutes.equals(addDataString)) {
                index++;
            } else {
                positionIndex = index;
            }
            for (WheelView wheelView : wheelViews) {

                wheelView.addData(addDataString);

            }
        }
        return positionIndex;
    }

    //设置时间 -- 小时
    private int setHouts(String currentHours, WheelView... wheelViews) {
        int index = 0;
        int positionIndex = 0;
        for (int i = 0; i < 24; i++) {
            String addDataString;
            if (i < 10) {
                addDataString = "0" + i;
            } else {
                addDataString = i + "";
            }
            if (!currentHours.equals(addDataString)) {
                index++;
            } else {
                positionIndex = index;
            }
            for (WheelView wheelView : wheelViews) {
                wheelView.addData(addDataString);
            }
        }
        return positionIndex;
    }

    //设置时间节点 -- 30分钟节点时间
    private int setMinutesInterval30(String currentTime, WheelView... wheelViews) {
        int index = 0;
        int positionIndex = 0;
        for (String time : times) {
            if (currentTime.equals(time)) {
                positionIndex = index;
            } else {
                index++;
            }
            for (WheelView wheelView : wheelViews) {
                wheelView.addData(time);
            }
        }
        return positionIndex;
    }

    //设置时间节点 -- 30分钟节点时间
    private int setMinutesInterval30(int startIndex, int endIndex, String currentTime, WheelView... wheelViews) {
        int index = 0;
        int positionIndex = 0;
        for (int i = startIndex; i < endIndex; i++) {
            if (currentTime.equals(times[i])) {
                positionIndex = index;
            } else {
                index++;
            }
            for (WheelView wheelView : wheelViews) {
                wheelView.addData(times[i]);
            }
        }
        return positionIndex;
    }
    //设置年月日

    private int currentYearInt = 0;
    private int currentMonthInt = 0;
    private int currentDayInt = 0;


}

